package handler

import (
	"github.com/gin-gonic/gin"
	"path/filepath"
	"tie/pkg"
)

func Upload(r *gin.Context) {
	file, err := r.FormFile("image")
	if err != nil {
		return
	}

	ext := filepath.Ext(file.Filename)
	if ext != ".png" && ext != ".jpg" {
		r.JSON(400, &Res{
			Code:    400,
			Message: "图片格式不对",
			Data:    nil,
		})
		return
	}

	upload, err := pkg.Upload(file)
	if err != nil {
		return
	}
	r.JSON(200, &Res{
		Code:    200,
		Message: "图片上传成功",
		Data:    upload,
	})
}
